<template>
  <div>
    <h4>生产过程确认（前配）：</h4>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="beforeColumns"
      :dataSource="beforeList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="beforeDetail(record)">详情</a>
      </template>
    </a-table>
    <h4>生产过程确认（后配）：</h4>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="afterColumns"
      :dataSource="afterList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="afterDetail(record)">详情</a>
      </template>
    </a-table>
    <h4>包装过程确认：</h4>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="packageColumns"
      :dataSource="packageList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="packageDetail(record)">详情</a>
      </template>
    </a-table>
    <h4>包装现场首件检：</h4>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="sceneColumns"
      :dataSource="sceneList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="sceneDetail(record)">详情</a>
      </template>
    </a-table>
    <erp-production-process-confirmation-before-modal ref="beforeForm" />
    <erp-production-process-confirmation-after-modal ref="afterForm" />
    <erp-package-process-confirmation-modal ref="packageForm" />
    <erp-package-first-confirm-modal ref="sceneForm" />
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'
import ErpProductionProcessConfirmationBeforeModal from '@/views/erp/manufactureconfirm/productionconfirmationbefore/modules/ErpProductionProcessConfirmationBeforeModal.vue'
import ErpProductionProcessConfirmationAfterModal from '@/views/erp/manufactureconfirm/productionconfirmationbefore/modules/ErpProductionProcessConfirmationBeforeModal.vue'
import ErpPackageProcessConfirmationModal from '@/views/erp/manufactureconfirm/packageprocessconfirmation/modules/ErpPackageProcessConfirmationModal.vue'
import ErpPackageFirstConfirmModal from '@/views/erp/manufactureconfirm/firstconfirm/modules/ErpPackageFirstConfirmModal.vue'

export default {
  name: 'proprocess',
  components: {
    ErpProductionProcessConfirmationBeforeModal,
    ErpProductionProcessConfirmationAfterModal,
    ErpPackageProcessConfirmationModal,
    ErpPackageFirstConfirmModal,
  },
  data() {
    return {
      description: '生产过程确认',
      beforeList: [],
      beforeColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '确认记录单号',
          align: 'center',
          dataIndex: 'confirmCode',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '生产班组',
          align: 'center',
          dataIndex: 'team_dictText',
        },
        {
          title: '核查人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '核查部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '核查时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : dayjs(text).format('YYYY-MM-DD')
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      afterList: [],
      afterColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '确认记录单号',
          align: 'center',
          dataIndex: 'confirmCode',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '生产班组',
          align: 'center',
          dataIndex: 'team_dictText',
        },
        {
          title: '核查人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '核查部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '核查时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : dayjs(text).format('YYYY-MM-DD')
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      packageList: [],
      packageColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '确认记录单号',
          align: 'center',
          dataIndex: 'confirmCode',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderCode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '包装车间',
          align: 'center',
          dataIndex: 'packshopCode_dictText',
        },
        {
          title: '包装班组',
          align: 'center',
          dataIndex: 'team_dictText',
        },
        {
          title: '核查人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '核查部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '核查时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      sceneList: [],
      sceneColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '确认记录单号',
          align: 'center',
          dataIndex: 'confirmCode',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planCode',
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderCode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workshopCode_dictText',
        },
        {
          title: '包装车间',
          align: 'center',
          dataIndex: 'packshopCode_dictText',
        },
        {
          title: '包装班组',
          align: 'center',
          dataIndex: 'team_dictText',
        },
        {
          title: '核查人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '核查部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '核查时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        before: '/packagefirstconfirm/erpPackageFirstConfirm/beforeList',
        after: '/packagefirstconfirm/erpPackageFirstConfirm/afterList',
        package: '/packagefirstconfirm/erpPackageFirstConfirm/packageList',
        scene: '/packagefirstconfirm/erpPackageFirstConfirm/sceneList',
      },
    }
  },

  methods: {
    loadProprocessData(batchNumber) {
      this.loadBeforeData(batchNumber)
      this.loadAfterData(batchNumber)
      this.loadPackageData(batchNumber)
      this.loadSceneData(batchNumber)
    },
    loadBeforeData(batchNumber) {
      this.beforeList = []
      if (batchNumber) {
        getAction(this.url.before, { batchNumber: batchNumber }).then((res) => {
          if (res.success) {
            this.beforeList = res.result.records || res.result || []
          }
        })
      }
    },
    loadAfterData(batchNumber) {
      this.afterList = []
      if (batchNumber) {
        getAction(this.url.after, { batchNumber: batchNumber }).then((res) => {
          if (res.success) {
            this.afterList = res.result.records || res.result || []
          }
        })
      }
    },
    loadPackageData(batchNumber) {
      this.packageList = []
      if (batchNumber) {
        getAction(this.url.package, { batchNumber: batchNumber }).then((res) => {
          if (res.success) {
            this.packageList = res.result.records || res.result || []
          }
        })
      }
    },
    loadSceneData(batchNumber) {
      this.sceneList = []
      if (batchNumber) {
        getAction(this.url.scene, { batchNumber: batchNumber }).then((res) => {
          if (res.success) {
            this.sceneList = res.result.records || res.result || []
          }
        })
      }
    },
    beforeDetail: function (record) {
      this.$refs.beforeForm.edit(record)
      this.$refs.beforeForm.title = '详情'
      this.$refs.beforeForm.disableSubmit = true
    },
    afterDetail: function (record) {
      this.$refs.afterForm.edit(record)
      this.$refs.afterForm.title = '详情'
      this.$refs.afterForm.disableSubmit = true
    },
    packageDetail: function (record) {
      this.$refs.packageForm.edit(record)
      this.$refs.packageForm.title = '详情'
      this.$refs.packageForm.disableSubmit = true
    },
    sceneDetail: function (record) {
      this.$refs.sceneForm.edit(record)
      this.$refs.sceneForm.title = '详情'
      this.$refs.sceneForm.disableSubmit = true
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
</style>
